from django.db import models

# Create your models here.
class BookInfo(models.Model):
    title = models.CharField(max_length=50)
    reader  = models.CharField(max_length=50)
    class Meta:
        db_table = "book"
    def __str__(self):
        return self.title



class HeroInfo(models.Model):
    name = models.CharField(max_length=20)
    bookid = models.ForeignKey(to=BookInfo,to_field="id",on_delete=models.CASCADE,related_name="bookinfo",db_constraint=False)  # 定义外键
    class Meta:
        db_table='hero'
    def __str__(self):
        return self.name

    @property
    def bookName(self):
        return self.bookinfo.values()
